package com.dongdong.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongdong.data.Page;
import com.dongdong.mapper.TbContentMapper;
import com.dongdong.pojo.TbContent;
import com.dongdong.pojo.TbContentExample;
import com.dongdong.service.ContentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Arrays;
import java.util.List;

@Service
@org.springframework.stereotype.Service
public class ContentServiceImpl implements ContentService {
    @Autowired
    private TbContentMapper tbContentMapper;

    @Override
    public Page<TbContent> selectInfo(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<TbContent> contentList = tbContentMapper.selectByExample(null);
        PageInfo<TbContent> info = new PageInfo<>(contentList);
        return new Page<>(info.getPageNum(),info.getPageSize(),info.getTotal(),info.getPages(),info.getList());
    }

    @Override
    public int deleteBatch(Long[] ids) {
        TbContentExample te = new TbContentExample();
        te.createCriteria().andIdIn(Arrays.asList(ids));
        return tbContentMapper.deleteByExample(te);
    }

    @Override
    public TbContent selectById(Long id) {
        return tbContentMapper.selectByPrimaryKey(id);
    }

    @Override
    public int insert(TbContent tbContent) {
        return tbContentMapper.insert(tbContent);
    }

    @Override
    public int updateInfo(TbContent tbContent) {
        return tbContentMapper.updateByPrimaryKey(tbContent);
    }
    //轮播图
    @Override
    public List<TbContent> selectByCategoryId() {
        TbContentExample te = new TbContentExample();
        te.createCriteria().andCategoryIdEqualTo(1L);
        return tbContentMapper.selectByExample(te);
    }

    @Override
    public List<TbContent> selectyourLike() {
        TbContentExample te = new TbContentExample();
        te.createCriteria().andCategoryIdEqualTo(4L);
        return tbContentMapper.selectByExample(te);

    }

    @Override
    public List<TbContent> selectRecommed() {
        TbContentExample te = new TbContentExample();
        te.createCriteria().andCategoryIdEqualTo(2L);
        return tbContentMapper.selectByExample(te);

    }
}
